package com.liukai.bishe.ui.fragment;

import android.content.Context;
import android.view.View;

import com.liukai.bishe.R;
import com.liukai.bishe.model.doman.transaction.Transaction;
import com.liukai.bishe.model.doman.transaction.TransactionRankList;
import com.liukai.bishe.model.doman.transaction.TransactionTotal;
import com.liukai.bishe.presenter.transactionPresenter.ITransactionPresenter;
import com.liukai.bishe.presenter.transactionPresenter.impl.ITransactionPresenterImpl;
import com.liukai.bishe.ui.adapter.RankListAdapter;
import com.liukai.bishe.view.ITransactionCallBack;

import java.util.ArrayList;
import java.util.List;

import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import androidx.viewpager.widget.ViewPager;
import butterknife.BindView;

public class SettingFragment extends BaseFragment implements ITransactionCallBack {

    private Context mContext;

    @BindView(R.id.recyclerView)
    public RecyclerView mRecyclerView;

    private List<TransactionRankList> mTransactionRankListList;
    private ITransactionPresenter mITransactionPresenter;

    // 获取上下文
    @Override
    protected Context getFragmentContext(View view) {
        mContext = view.getContext();
        return null;
    }

    @Override
    protected int getLayoutId() {
        return R.layout.fragment_setting;
    }

    @Override
    protected void initDate() {

        mITransactionPresenter = new ITransactionPresenterImpl();
        mITransactionPresenter.registerCallback(this);
        mITransactionPresenter.getRankList();
        mTransactionRankListList = new ArrayList<>();

    }

    @Override
    protected void initAdapter(View view) {


    }

    @Override
    public void resultTrsaction(Object object) {

    }

    @Override
    public void resultTransactionTotal(List<TransactionTotal> transactionTotalList) {

    }

    @Override
    public void result(Object object) {
        mTransactionRankListList = (List<TransactionRankList>)object;
        RankListAdapter rankListAdapter = new RankListAdapter(mTransactionRankListList,mContext);
        LinearLayoutManager linearLayoutManager = new LinearLayoutManager(mContext);
        mRecyclerView.setLayoutManager(linearLayoutManager);
        mRecyclerView.setAdapter(rankListAdapter);
    }

    @Override
    protected void release() {
        super.release();
        if (mITransactionPresenter != null) {
            mITransactionPresenter = null;
        }
    }
}
